﻿Public Class frmCartera

    
    Private Sub dtpFecha_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpFecha.ValueChanged
        
        Dim sError As String = ""

        sError = CargarVistaPoliza(CaserDataSet.VistaPolizas, New Date(3099, 1, 1))

        If sError <> "" Then
            MessageBox.Show(sError, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        VistaPolizasBindingSource.Filter = "competencia = 'false'"
        lblBeneficios.Text = "Beneficios: 0,00 €"
        Dim acum As Double = 0.0
        For Each row As caserDataSet.VistaPolizasRow In CaserDataSet.VistaPolizas.Select("competencia = 'false'")
            Dim pago As Integer

            Select Case row.formapago
                Case "MENSUAL"
                    pago = 1
                Case "TRIMESTRAL"
                    pago = 3
                Case "SEMESTRAL"
                    pago = 6
                Case "ANUAL"
                    pago = 12

            End Select
            If (dtpFecha.Value.Month - Date.Parse(row.fechacontratacion).Month) Mod pago = 0 Then

                acum += row.prima * (row.comision / 100)
            Else
                CaserDataSet.VistaPolizas.Rows.Remove(row)
            End If
        Next
        lblBeneficios.Text = "Beneficios: " & acum & " €"


    End Sub

    Private Sub frmCartera_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'CaserDataSet.VistaPolizaFiltro' Puede moverla o quitarla según sea necesario.
        dtpFecha_ValueChanged(dtpFecha, New EventArgs)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PrintDGV.Print_DataGridView(dgPoliza, ("Mi cartera del mes de " & MonthName(dtpFecha.Value.Month) & " de " & dtpFecha.Value.Year), lblBeneficios.Text)
    End Sub
End Class